package org.abacus.platform.util;

import java.util.List;

public class PagingUtil {

	private PagingUtil() {
		super();
	}

	public final static <T> List<T> pagingList(List<T> data, int pageSize, int startIndex) {
		if (CollectionUtil.isEmpty(data)) {
			return data;
		}
		if (startIndex < 0) {
			startIndex = 0;
		}
		if (pageSize < 0) {
			pageSize = 20;
		}
		int size = data.size();
		if (size <= pageSize) {
			return data;
		}
		if (startIndex + pageSize <= size) {
			return data.subList(startIndex, startIndex + pageSize);
		}

		if (startIndex + pageSize > size) {
			return data.subList(startIndex, size);
		}
		return data;
	}
}